// ChangePassword.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "ChangePassword.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChangePassword dialog


CChangePassword::CChangePassword(CWnd* pParent /*=NULL*/)
	: CDialog(CChangePassword::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChangePassword)
	m_NewPasswdConfirm = _T("");
	m_NewPasswd = _T("");
	//}}AFX_DATA_INIT
}


void CChangePassword::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChangePassword)
	DDX_Text(pDX, IDC_NewPasswdConfirm, m_NewPasswdConfirm);
	DDV_MaxChars(pDX, m_NewPasswdConfirm, 4);
	DDX_Text(pDX, IDC_NewPasswd, m_NewPasswd);
	DDV_MaxChars(pDX, m_NewPasswd, 4);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChangePassword, CDialog)
	//{{AFX_MSG_MAP(CChangePassword)
	ON_EN_CHANGE(IDC_NewPasswd, OnChangeNewPasswd)
	ON_EN_CHANGE(IDC_NewPasswdConfirm, OnChangeNewPasswdConfirm)
	ON_BN_CLICKED(IDC_PasswordProtection, OnPasswordProtection)
	ON_BN_CLICKED(ID_ChangePasswdOK, OnChangePasswdOK)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChangePassword message handlers

BOOL CChangePassword::OnInitDialog() 
{
	CDialog::OnInitDialog();

	if (!m_SetPassword.Create(this))
		g_GlobalObj.UIWriteLog("m_SetPassword.Create Error");

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CChangePassword::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

void CChangePassword::OnChangeNewPasswd() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	if (!m_SetPassword.NewPasswdChanged())
		g_GlobalObj.UIWriteLog("m_SetPassword.NewPasswdChanged Error");

	
}

void CChangePassword::OnChangeNewPasswdConfirm() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	if (!m_SetPassword.ConfirmPasswdChanged())
		g_GlobalObj.UIWriteLog("m_SetPassword.ConfirmPasswdChanged Error");
	
}

void CChangePassword::OnPasswordProtection() 
{
	if (!m_SetPassword.PasswdProtectChanged())
		g_GlobalObj.UIWriteLog("m_SetPassword.PasswdProtectChanged Error");
	
}

void CChangePassword::OnChangePasswdOK() 
{
	CString szMsg;

	if (!m_SetPassword.Set())
	{
		g_GlobalObj.UIWriteLog("m_SetPassword.Set Error");
	}
	else
	{
		CDialog::OnOK();
	}	
}
